package com.siyue.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.siyue.dao.BookReviewDAO;
import com.siyue.dao.DAOFactory;
import com.siyue.model.Book;
import com.siyue.model.BookReview;
import com.siyue.util.DataBase;

public class BookReviewServlet extends TopServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String bookId=request.getParameter("bookId");
		String parentCategoryId=request.getParameter("parentCategoryId");
		String path=request.getParameter("path");
		String memberId=request.getParameter("memberId");
		String reviewImg=request.getParameter("reviewImg");
		String reviewContent =request.getParameter("reviewContent");
		BookReview bookReview=new BookReview();
		if(bookId!=null&&bookId.length()>0){
			bookReview.setBookId(Integer.parseInt(bookId));
		}
		if(memberId!=null&&memberId.length()>0){
			bookReview.setMemberId(Integer.parseInt(memberId));
		}
		if(reviewImg!=null&&reviewImg.length()>0){
			bookReview.setReviewImg(Integer.parseInt(reviewImg));
		}
		bookReview.setReviewContent(reviewContent);
		BookReviewDAO bookReviewDao=DAOFactory.getBookReviewDAO();
		try{
			bookReviewDao.addBookReview(bookReview);
			
			request.setAttribute("bookId",bookId);
			request.setAttribute("parentCategoryId",parentCategoryId);
			request.setAttribute("path",path);
			this.forward(request, response, "/SysBookServlet?method=viewBook");
			
			DataBase.commit();
		}catch(Exception e){
			DataBase.rollback();
			e.printStackTrace();
		}
		DataBase.releaseConnection();
		
	}
}
